package com.moran.deepseek.controller;

import com.moran.deepseek.domain.ChatResult;
import com.moran.deepseek.service.ChatService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @Description
 * @Author wnf
 * @Date 2025-07-17
 */
@RestController
@RequestMapping("/api/chat")
public class ChatController {

    @Resource
    private ChatService chatService;

    @PostMapping("/one")
    public String chat(@RequestBody String message) {
        try {
            return ChatResult.success(chatService.sendMessage(message)).toJson();
        } catch (IOException e) {
            throw new RuntimeException("调用DeepSeek API失败: " + e.getMessage(), e);
        }
    }

    // 多轮对话
    @PostMapping("/completion")
    public String chatCompletion(@RequestBody String param) {
        try {
            return ChatResult.success(chatService.chatCompletion(param)).toJson();
        } catch (IOException e) {
            throw new RuntimeException("调用DeepSeek API失败: " + e.getMessage(), e);
        }
    }
}
